// pages/index/index.js
import Toast from '@vant/weapp/toast/toast';
import {request} from '../../utils/request.js'

Page({
  onReady(){
    this.findBindStudent()
  },
  data: {
    array:[],
    childrenindex:1
  },
  findBindStudent(){//查询学生信息
    let vm = this
    request({
      url:'/review-paper/system/user/findBindStudent',
      data:{},
      success (res) {
        if(res.data.status == 1){
            wx.setStorage({
              key:"findBindStudent",
              data:res.data.data
            })
            vm.findExamScoreByStudentId(res.data.data)
        }else{
          Toast.fail(res.data.msg);
        }
      }
    })
  },
  findExamScoreByStudentId(data){//学生考试列表
    let vm = this
    this.data.array = []
    data.forEach(item => {
      request({
        url:'/review-paper/exam/findExamScoreByStudentId',
        data:{
          studentId:item.id
        },
        success (res) {
          if(res.data.status == 1){
            res.data.data.forEach(val => {
              val.realName = item.realName
              val.schoolName = item.schoolName
              val.subjectScoreList.forEach(va=>{
                va.studentId = item.id
                va.id = va.subjectExamId
              })
            })
            vm.data.array = vm.data.array.concat(res.data.data)
            vm.setData({
              array: vm.data.array
            })
          }else{
            Toast.fail(res.data.msg);
          }
        }
      })
    })
  },
  //
  //跳转试卷
  navigateToView(e){
    //传递科目信息
    wx.setStorage({
      key:'subjectInfo',
      data:e.target.dataset.data
    })
    wx.navigateTo({
      url: '../studentScoreView/studentScoreView'
    })
  },
  //跳转视频号
  navigateToChannel: function() {
    wx.openChannelsUserProfile({
      finderUserName:getApp().globalData.sphId,
      complete(e){
        console.log(e)
      }
    })
  },
    //退出登录
    loginOut(){
      wx.removeStorage({key:'token'})
      wx.removeStorage({key:'userInfo'})
      wx.removeStorage({key:'schoolInfo'})
      getApp().globalData.header.accessToken = ''
      wx.redirectTo({
        url: '../login/login',
      })
    }
})
